/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.seagate.app.servlet;

import com.seagate.app.bean.SliderReportBean;
import com.seagate.app.manager.SliderManager;
import java.awt.Color;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.math.stat.descriptive.moment.StandardDeviation;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.block.BlockBorder;
import org.jfree.chart.block.BlockContainer;
import org.jfree.chart.block.BorderArrangement;
import org.jfree.chart.block.EmptyBlock;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.DatasetRenderingOrder;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.chart.title.CompositeTitle;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.urls.PieURLGenerator;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.ui.RectangleEdge;
import org.jfree.ui.RectangleInsets;
import org.jfree.util.Rotation;

/**
 *
 * @author 452530
 */
public class ReportChart extends HttpServlet {

    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            String action = request.getParameter("action");
            if ("incomming".equalsIgnoreCase(action)) {

                 randerChart(request, response, sliderTimeData(), createDataset2());
               // randerPieChart(request, response, priorityDataset());
                createTable(request, response);

            }else if ("testchart".equalsIgnoreCase(action)) {

                 randerChart(request, response, sliderTimeData(), createDataset2());
               // randerPieChart(request, response, priorityDataset());
                createTable(request, response);

            }
        } finally {
            out.close();
        }
    }

    private void createTable(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        SliderManager sldmg = new SliderManager();
        DecimalFormat dfm = new java.text.DecimalFormat("0.00");
        out.println("<table bgcolor=\"#CCCCCC\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">");
        out.println("<tr><td>");
        out.println("<table bgcolor=\"#6699CC\" cellpadding=\"3\" cellspacing=\"0\" border=\"0\" width=\"100%\">");
        String[][] productNameTab = {
            {"TDT", "TDT"},
            {"TST", "TST"},
            {"RTD&TDM", "RTD','TDM"}
        };

        for (int ln = 0; ln < productNameTab.length; ln++) {
            List tdtlist = sldmg.IncomingBinReport(productNameTab[ln][1]);
            out.println("<tr bgcolor=\"#eeeeee\">");
            out.println("<td>");
            out.println("<table bgcolor=\"#cccccc\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">");
            out.println("<tr><td>");
            out.println("<table bgcolor=\"#cccccc\" cellpadding=\"3\" cellspacing=\"1\" border=\"0\" width=\"100%\">");
            out.println("<tr bgcolor=\"#0000FF\">");
            out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;No.&nbsp;</font></td>");
            out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;BIN&nbsp;</font></td>");
            out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Product&nbsp;</font></td>");
            out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Priority&nbsp;</font></td>");
            out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Document Delay (Day)&nbsp;</font></td>");
            out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Slider Gap (Day)&nbsp;</font></td>");
            out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;HGA Queue(Day)&nbsp;</font></td>");
            out.println("</tr>");
            int count = 0;
            double tdtDocDelay = 0;
            double tdtSldGap = 0;
            double tdtHgaQ = 0;
            int indexparam=tdtlist.size();
            double tdtDocDelay2[] = new double[indexparam];
            double tdtSldGap2[] = new double[indexparam];
            double tdtHgaQ2[] = new double[indexparam];
            
            int countDocDelay = 0;
            int countSldGap = 0;
            int countHgaQ = 0;
            for (int i = 0; i < tdtlist.size(); i++) {
                if (count % 2 == 0) {
                    out.println("<tr bgcolor=\"#ffffff\">");
                } else {
                    out.println("<tr bgcolor=\"#ccffff\">");
                }
                SliderReportBean tdt = (SliderReportBean) tdtlist.get(i);
                out.println("<td>&nbsp;" + (i+1) + "&nbsp;</td>");
                out.println("<td>&nbsp;" + tdt.getBinId() + "&nbsp;</td>");
                out.println("<td>&nbsp;" + tdt.getProductfamily() + "&nbsp;</td>");
                out.println("<td>&nbsp;" + tdt.getHgaPriority() + "&nbsp;</td>");
                out.println("<td>&nbsp;" + dfm.format(tdt.getDocDelay()) + "&nbsp;</td>");
                out.println("<td>&nbsp;" + dfm.format(tdt.getSliderGap()) + "&nbsp;</td>");
                out.println("<td>&nbsp;" + dfm.format(tdt.getHgaQueue()) + "&nbsp;</td>");
                out.println("</tr>");
                tdtDocDelay = tdtDocDelay + tdt.getDocDelay();
                tdtDocDelay2[i]=tdt.getDocDelay();
                tdtSldGap = tdtSldGap + tdt.getSliderGap();
                tdtSldGap2[i]=tdt.getSliderGap();
                tdtHgaQ = tdtHgaQ + tdt.getHgaQueue();
                tdtHgaQ2[i]=tdt.getHgaQueue();
                if (tdt.getDocDelay() > 0) {
                    countDocDelay = countDocDelay + 1;
                }
                if (tdt.getSliderGap() > 0) {
                    countSldGap = countSldGap + 1;
                }
                if (tdt.getHgaQueue() > 0) {
                    countHgaQ = countHgaQ + 1;
                }
                count++;
            }


            out.println("<tr bgcolor=\"#ffffff\"  >");
            out.println("<td  ><b>&nbsp;Total &nbsp;</b></td>");
            out.println("<td  ><b>&nbsp; ALL (" + count + ")&nbsp;</b></td>");
            out.println("<td  ><b>&nbsp; Average  &nbsp;</b></td>");
            out.println("<td  ><b>&nbsp;  &nbsp;</b></td>");
//            out.println("<td  ><b>&nbsp;" + dfm.format(tdtDocDelay) + " ("+countDocDelay+" BIN)&nbsp;</b></td>");
//            out.println("<td  ><b>&nbsp;" + dfm.format(tdtSldGap) + " ("+countSldGap+" BIN)&nbsp;</b></td>");
//            out.println("<td  ><b>&nbsp;" + dfm.format(tdtHgaQ) + " ("+countHgaQ+" BIN)&nbsp;</b></td>");
            out.println("<td  ><b>&nbsp;" + dfm.format(tdtDocDelay/count) + " &nbsp;</b></td>");
            out.println("<td  ><b>&nbsp;" + dfm.format(tdtSldGap/count) + " &nbsp;</b></td>");
            out.println("<td  ><b>&nbsp;" + dfm.format(tdtHgaQ/count) + "  &nbsp;</b></td>");
            out.println("</tr>");
                      StandardDeviation statcal=new StandardDeviation();
            out.println("<tr bgcolor=\"#ffffff\"  >");
            out.println("<td  ><b>&nbsp;Sigma &nbsp;</b></td>");
            out.println("<td  ><b>&nbsp; ALL (" + count + ")&nbsp;</b></td>");
            out.println("<td  ><b>&nbsp; STDEV.  &nbsp;</b></td>");
            out.println("<td  ><b>&nbsp;  &nbsp;</b></td>");
//            out.println("<td  ><b>&nbsp;" + dfm.format(tdtDocDelay) + " ("+countDocDelay+" BIN)&nbsp;</b></td>");
//            out.println("<td  ><b>&nbsp;" + dfm.format(tdtSldGap) + " ("+countSldGap+" BIN)&nbsp;</b></td>");
//            out.println("<td  ><b>&nbsp;" + dfm.format(tdtHgaQ) + " ("+countHgaQ+" BIN)&nbsp;</b></td>");
            out.println("<td  ><b>&nbsp;" + dfm.format(statcal.evaluate(tdtDocDelay2)) + " &nbsp;</b></td>");
            out.println("<td  ><b>&nbsp;" + dfm.format(statcal.evaluate(tdtSldGap2)) + " &nbsp;</b></td>");
            out.println("<td  ><b>&nbsp;" + dfm.format(statcal.evaluate(tdtHgaQ2)) + "  &nbsp;</b></td>");
            out.println("</tr>");
            
            
            out.println("</table>");
            out.println("</td></tr>");
            out.println("</table>");
            out.println("</td>");
            out.println("</tr>");
        }
        out.println("</table>");
        out.println("</td></tr>");
        out.println("</table>");
    }

  private  PieDataset priorityDataset()
  {

        
        SliderManager sldmg = new SliderManager();

        DefaultPieDataset localDefaultPieDataset = new DefaultPieDataset();

        List piolist = sldmg.IncomingBinReport("TDT','TST','RTD','TDM");
        int priority9 = 0;
        int priority1 = 0;
        int priority0 = 0;
        for (int i = 0; i < piolist.size(); i++) {
            SliderReportBean tdt = (SliderReportBean) piolist.get(i);
            if( (tdt.getDocDelay() > 0)||(tdt.getSliderGap() > 0)||(tdt.getHgaQueue() > 0)) {
                if(tdt.getHgaPriority()==9){
                    priority9++;
                }else if(tdt.getHgaPriority()==1){
                    priority1++;
                }else{
                    priority0++;
                }
            }

        }



    localDefaultPieDataset.setValue("Priority 9", new Double(priority9));
    localDefaultPieDataset.setValue("Priority 1", new Double(priority1));
    localDefaultPieDataset.setValue("Priority 0", new Double(priority0));

    return localDefaultPieDataset;
  }
  private void randerPieChart(HttpServletRequest request, HttpServletResponse response, PieDataset paramPieDataset)
            throws ServletException, IOException {
//        JFreeChart localJFreeChart = ChartFactory.createBarChart("Bin Report ", "Product", "No. of BIN", dataset1, PlotOrientation.VERTICAL, false, true, false);
//        CategoryPlot localCategoryPlot = (CategoryPlot) localJFreeChart.getPlot();
      JFreeChart localJFreeChart = ChartFactory.createPieChart3D("Bin Report By Priority", paramPieDataset, true, true, true);
    PiePlot3D localPiePlot3D = (PiePlot3D)localJFreeChart.getPlot();
 
    localPiePlot3D.setDarkerSides(true);
    localPiePlot3D.setStartAngle(290.0D);
    localPiePlot3D.setDirection(Rotation.CLOCKWISE);
    localPiePlot3D.setForegroundAlpha(0.5F);
    localPiePlot3D.setNoDataMessage("No data to display");
    localPiePlot3D.setBackgroundPaint(Color.decode("#FFFFFF"));

//        localCategoryPlot.setDomainGridlinePaint(Color.decode("#99CCCC"));
//        localCategoryPlot.setRangeGridlinePaint(Color.decode("#99CCCC"));
//        localCategoryPlot.setBackgroundPaint(Color.decode("#FFFFCC"));
//
//        CategoryDataset localCategoryDataset = dataset2;
//        localCategoryPlot.setDataset(1, localCategoryDataset);
//        localCategoryPlot.mapDatasetToRangeAxis(1, 1);
//        CategoryAxis localCategoryAxis = localCategoryPlot.getDomainAxis();
//        localCategoryAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
//        NumberAxis localNumberAxis = new NumberAxis("Days/BIN");
//        localCategoryPlot.setRangeAxis(1, localNumberAxis);
//        LineAndShapeRenderer localLineAndShapeRenderer = new LineAndShapeRenderer();
//        localLineAndShapeRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
//
//        localCategoryPlot.setRenderer(1, localLineAndShapeRenderer);
//        localCategoryPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
//
//
//        LegendTitle localLegendTitle1 = new LegendTitle(localCategoryPlot.getRenderer(0));
//        localLegendTitle1.setMargin(new RectangleInsets(2.0D, 2.0D, 2.0D, 2.0D));
//        localLegendTitle1.setFrame(new BlockBorder());
//        LegendTitle localLegendTitle2 = new LegendTitle(localCategoryPlot.getRenderer(1));
//        localLegendTitle2.setMargin(new RectangleInsets(2.0D, 2.0D, 2.0D, 2.0D));
//        localLegendTitle2.setFrame(new BlockBorder());
//        BlockContainer localBlockContainer = new BlockContainer(new BorderArrangement());
//        localBlockContainer.add(localLegendTitle1, RectangleEdge.LEFT);
//        localBlockContainer.add(localLegendTitle2, RectangleEdge.RIGHT);
//        localBlockContainer.add(new EmptyBlock(2000.0D, 0.0D));
//        CompositeTitle localCompositeTitle = new CompositeTitle(localBlockContainer);
//        localCompositeTitle.setPosition(RectangleEdge.BOTTOM);
//        localJFreeChart.addSubtitle(localCompositeTitle);

        String filename = "";
        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        filename = ServletUtilities.saveChartAsPNG(localJFreeChart, 500, 350, info, request.getSession());
        PrintWriter out = new PrintWriter(response.getWriter());
        ChartUtilities.writeImageMap(out, filename, info, false);
        // ChartUtilities.writeBufferedImageAsPNG(sos, image);
        out.println("<img src='" + request.getContextPath() + "/servlet/DisplayChart?filename=" + filename + "' border=0 usemap='#" + filename + "' />");


    }
    private void randerChart(HttpServletRequest request, HttpServletResponse response, CategoryDataset dataset1, CategoryDataset dataset2)
            throws ServletException, IOException {
        JFreeChart localJFreeChart = ChartFactory.createBarChart("Bin Report ", "Product", "No. of BIN", dataset1, PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot localCategoryPlot = (CategoryPlot) localJFreeChart.getPlot();

        localCategoryPlot.setDomainGridlinePaint(Color.decode("#99CCCC"));
        localCategoryPlot.setRangeGridlinePaint(Color.decode("#99CCCC"));
        localCategoryPlot.setBackgroundPaint(Color.decode("#FFFFCC"));

        CategoryDataset localCategoryDataset = dataset2;
        localCategoryPlot.setDataset(1, localCategoryDataset);
        localCategoryPlot.mapDatasetToRangeAxis(1, 1);
        CategoryAxis localCategoryAxis = localCategoryPlot.getDomainAxis();
        localCategoryAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
        NumberAxis localNumberAxis = new NumberAxis("Days/BIN");
        localCategoryPlot.setRangeAxis(1, localNumberAxis);
        LineAndShapeRenderer localLineAndShapeRenderer = new LineAndShapeRenderer();
        localLineAndShapeRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());

        localCategoryPlot.setRenderer(1, localLineAndShapeRenderer);
        localCategoryPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);


        LegendTitle localLegendTitle1 = new LegendTitle(localCategoryPlot.getRenderer(0));
        localLegendTitle1.setMargin(new RectangleInsets(2.0D, 2.0D, 2.0D, 2.0D));
        localLegendTitle1.setFrame(new BlockBorder());
        LegendTitle localLegendTitle2 = new LegendTitle(localCategoryPlot.getRenderer(1));
        localLegendTitle2.setMargin(new RectangleInsets(2.0D, 2.0D, 2.0D, 2.0D));
        localLegendTitle2.setFrame(new BlockBorder());
        BlockContainer localBlockContainer = new BlockContainer(new BorderArrangement());
        localBlockContainer.add(localLegendTitle1, RectangleEdge.LEFT);
        localBlockContainer.add(localLegendTitle2, RectangleEdge.RIGHT);
        localBlockContainer.add(new EmptyBlock(2000.0D, 0.0D));
        CompositeTitle localCompositeTitle = new CompositeTitle(localBlockContainer);
        localCompositeTitle.setPosition(RectangleEdge.BOTTOM);
        localJFreeChart.addSubtitle(localCompositeTitle);

        String filename = "";
        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        filename = ServletUtilities.saveChartAsPNG(localJFreeChart, 700, 450, info, request.getSession());
        PrintWriter out = new PrintWriter(response.getWriter());
        ChartUtilities.writeImageMap(out, filename, info, false);
        // ChartUtilities.writeBufferedImageAsPNG(sos, image);
        out.println("<img src='" + request.getContextPath() + "/servlet/DisplayChart?filename=" + filename + "' border=0 usemap='#" + filename + "' />");


    }
 private static CategoryDataset sliderTimeData2() {
        String str1 = "Slider Contribution";
        String str2 = "Wafer Gap";
        String str3 = "HGA Queue";
        String cate1 = "TDT";
        String cate2 = "TST";
        String cate3 = "RTD&TDM";
        SliderManager sldmg = new SliderManager();

        DefaultCategoryDataset localDefaultCategoryDataset = new DefaultCategoryDataset();

        List tdtlist = sldmg.IncomingBinReport("TDT");
        int tdtDocDelay = 0;
        int tdtSldGap = 0;
        int tdtHgaQ = 0;
        for (int i = 0; i < tdtlist.size(); i++) {
            SliderReportBean tdt = (SliderReportBean) tdtlist.get(i);
            if (tdt.getDocDelay() > 0) {
                tdtDocDelay = tdtDocDelay + 1;
            }
            if (tdt.getSliderGap() > 0) {
                tdtSldGap = tdtSldGap + 1;
            }
            if (tdt.getHgaQueue() > 0) {
                tdtHgaQ = tdtHgaQ + 1;
            }

        }

        localDefaultCategoryDataset.addValue(tdtDocDelay, str1, cate1);
        localDefaultCategoryDataset.addValue(tdtSldGap, str2, cate1);
        localDefaultCategoryDataset.addValue(tdtHgaQ, str3, cate1);

        List tstlist = sldmg.IncomingBinReport("TST");
        int tstDocDelay = 0;
        int tstSldGap = 0;
        int tstHgaQ = 0;
        for (int i = 0; i < tstlist.size(); i++) {
            SliderReportBean tst = (SliderReportBean) tstlist.get(i);
            if (tst.getDocDelay() > 0) {
                tstDocDelay = tstDocDelay + 1;
            }
            if (tst.getSliderGap() > 0) {
                tstSldGap = tstSldGap + 1;
            }
            if (tst.getHgaQueue() > 0) {
                tstHgaQ = tstHgaQ + 1;
            }
        }

        localDefaultCategoryDataset.addValue(tstDocDelay, str1, cate2);
        localDefaultCategoryDataset.addValue(tstSldGap, str2, cate2);
        localDefaultCategoryDataset.addValue(tstHgaQ, str3, cate2);

        List trtlist = sldmg.IncomingBinReport("RTD','TDM");
        int trtDocDelay = 0;
        int trtSldGap = 0;
        int trtHgaQ = 0;
        for (int i = 0; i < trtlist.size(); i++) {
            SliderReportBean trt = (SliderReportBean) trtlist.get(i);
            if (trt.getDocDelay() > 0) {
                trtDocDelay = trtDocDelay + 1;
            }
            if (trt.getSliderGap() > 0) {
                trtSldGap = trtSldGap + 1;
            }
            if (trt.getHgaQueue() > 0) {
                trtHgaQ = trtHgaQ + 1;
            }
        }

        localDefaultCategoryDataset.addValue(trtDocDelay, str1, cate3);
        localDefaultCategoryDataset.addValue(trtSldGap, str2, cate3);
        localDefaultCategoryDataset.addValue(trtHgaQ, str3, cate3);


        return localDefaultCategoryDataset;
    }
    private static CategoryDataset sliderTimeData() {
        String str1 = "Doc Delay";
        String str2 = "Slider Gap";
        String str3 = "HGA Queue";
        String cate1 = "TDT";
        String cate2 = "TST";
        String cate3 = "RTD&TDM";
        SliderManager sldmg = new SliderManager();

        DefaultCategoryDataset localDefaultCategoryDataset = new DefaultCategoryDataset();

        List tdtlist = sldmg.IncomingBinReport("TDT");
        int tdtDocDelay = 0;
        int tdtSldGap = 0;
        int tdtHgaQ = 0;
        for (int i = 0; i < tdtlist.size(); i++) {
            SliderReportBean tdt = (SliderReportBean) tdtlist.get(i);
            if (tdt.getDocDelay() > 0) {
                tdtDocDelay = tdtDocDelay + 1;
            }
            if (tdt.getSliderGap() > 0) {
                tdtSldGap = tdtSldGap + 1;
            }
            if (tdt.getHgaQueue() > 0) {
                tdtHgaQ = tdtHgaQ + 1;
            }

        }

        localDefaultCategoryDataset.addValue(tdtDocDelay, str1, cate1);
        localDefaultCategoryDataset.addValue(tdtSldGap, str2, cate1);
        localDefaultCategoryDataset.addValue(tdtHgaQ, str3, cate1);

        List tstlist = sldmg.IncomingBinReport("TST");
        int tstDocDelay = 0;
        int tstSldGap = 0;
        int tstHgaQ = 0;
        for (int i = 0; i < tstlist.size(); i++) {
            SliderReportBean tst = (SliderReportBean) tstlist.get(i);
            if (tst.getDocDelay() > 0) {
                tstDocDelay = tstDocDelay + 1;
            }
            if (tst.getSliderGap() > 0) {
                tstSldGap = tstSldGap + 1;
            }
            if (tst.getHgaQueue() > 0) {
                tstHgaQ = tstHgaQ + 1;
            }
        }

        localDefaultCategoryDataset.addValue(tstDocDelay, str1, cate2);
        localDefaultCategoryDataset.addValue(tstSldGap, str2, cate2);
        localDefaultCategoryDataset.addValue(tstHgaQ, str3, cate2);

        List trtlist = sldmg.IncomingBinReport("RTD','TDM");
        int trtDocDelay = 0;
        int trtSldGap = 0;
        int trtHgaQ = 0;
        for (int i = 0; i < trtlist.size(); i++) {
            SliderReportBean trt = (SliderReportBean) trtlist.get(i);
            if (trt.getDocDelay() > 0) {
                trtDocDelay = trtDocDelay + 1;
            }
            if (trt.getSliderGap() > 0) {
                trtSldGap = trtSldGap + 1;
            }
            if (trt.getHgaQueue() > 0) {
                trtHgaQ = trtHgaQ + 1;
            }
        }

        localDefaultCategoryDataset.addValue(trtDocDelay, str1, cate3);
        localDefaultCategoryDataset.addValue(trtSldGap, str2, cate3);
        localDefaultCategoryDataset.addValue(trtHgaQ, str3, cate3);


        return localDefaultCategoryDataset;
    }

    private static CategoryDataset createDataset1() {
        String str1 = "S1";
        String str2 = "S2";
        String str3 = "S3";
        String str4 = "Category 1";
        String str5 = "Category 2";
        String str6 = "Category 3";
        String str7 = "Category 4";
        String str8 = "Category 5";
        String str9 = "Category 6";
        String str10 = "Category 7";
        String str11 = "Category 8";
        DefaultCategoryDataset localDefaultCategoryDataset = new DefaultCategoryDataset();
        localDefaultCategoryDataset.addValue(1.0D, str1, str4);
        localDefaultCategoryDataset.addValue(4.0D, str1, str5);
        localDefaultCategoryDataset.addValue(3.0D, str1, str6);
        localDefaultCategoryDataset.addValue(5.0D, str1, str7);
        localDefaultCategoryDataset.addValue(5.0D, str1, str8);
        localDefaultCategoryDataset.addValue(7.0D, str1, str9);
        localDefaultCategoryDataset.addValue(7.0D, str1, str10);
        localDefaultCategoryDataset.addValue(8.0D, str1, str11);
        localDefaultCategoryDataset.addValue(5.0D, str2, str4);
        localDefaultCategoryDataset.addValue(7.0D, str2, str5);
        localDefaultCategoryDataset.addValue(6.0D, str2, str6);
        localDefaultCategoryDataset.addValue(8.0D, str2, str7);
        localDefaultCategoryDataset.addValue(4.0D, str2, str8);
        localDefaultCategoryDataset.addValue(4.0D, str2, str9);
        localDefaultCategoryDataset.addValue(2.0D, str2, str10);
        localDefaultCategoryDataset.addValue(1.0D, str2, str11);
        localDefaultCategoryDataset.addValue(4.0D, str3, str4);
        localDefaultCategoryDataset.addValue(3.0D, str3, str5);
        localDefaultCategoryDataset.addValue(2.0D, str3, str6);
        localDefaultCategoryDataset.addValue(3.0D, str3, str7);
        localDefaultCategoryDataset.addValue(6.0D, str3, str8);
        localDefaultCategoryDataset.addValue(3.0D, str3, str9);
        localDefaultCategoryDataset.addValue(4.0D, str3, str10);
        localDefaultCategoryDataset.addValue(3.0D, str3, str11);
        return localDefaultCategoryDataset;
    }

    private static CategoryDataset createDataset2() {
        String str1 = "Doc Delay";
        String str2 = "Slider Gap";
        String str3 = "HGA Queue";
        String cate1 = "TDT";
        String cate2 = "TST";
        String cate3 = "RTD&TDM";
        SliderManager sldmg = new SliderManager();

        DefaultCategoryDataset localDefaultCategoryDataset = new DefaultCategoryDataset();

        List tdtlist = sldmg.IncomingBinReport("TDT");
        double tdtDocDelay = 0;
        double tdtSldGap = 0;
        double tdtHgaQ = 0;
        for (int i = 0; i < tdtlist.size(); i++) {
            SliderReportBean tdt = (SliderReportBean) tdtlist.get(i);
            tdtDocDelay = tdtDocDelay + tdt.getDocDelay();
            tdtSldGap = tdtSldGap + tdt.getSliderGap();
            tdtHgaQ = tdtHgaQ + tdt.getHgaQueue();
        }

        localDefaultCategoryDataset.addValue(tdtDocDelay / tdtlist.size(), str1, cate1);
        localDefaultCategoryDataset.addValue(tdtSldGap / tdtlist.size(), str2, cate1);
        localDefaultCategoryDataset.addValue(tdtHgaQ / tdtlist.size(), str3, cate1);

        List tstlist = sldmg.IncomingBinReport("TST");
        double tstDocDelay = 0;
        double tstSldGap = 0;
        double tstHgaQ = 0;
        for (int i = 0; i < tstlist.size(); i++) {
            SliderReportBean tst = (SliderReportBean) tstlist.get(i);
            tstDocDelay = tstDocDelay + tst.getDocDelay();
            tstSldGap = tstSldGap + tst.getSliderGap();
            tstHgaQ = tstHgaQ + tst.getHgaQueue();
        }

        localDefaultCategoryDataset.addValue(tstDocDelay / tstlist.size(), str1, cate2);
        localDefaultCategoryDataset.addValue(tstSldGap / tstlist.size(), str2, cate2);
        localDefaultCategoryDataset.addValue(tstHgaQ / tstlist.size(), str3, cate2);

        List trtlist = sldmg.IncomingBinReport("RTD','TDM");
        double trtDocDelay = 0;
        double trtSldGap = 0;
        double trtHgaQ = 0;
        for (int i = 0; i < trtlist.size(); i++) {
            SliderReportBean trt = (SliderReportBean) trtlist.get(i);
            trtDocDelay = trtDocDelay + trt.getDocDelay();
            trtSldGap = trtSldGap + trt.getSliderGap();
            trtHgaQ = trtHgaQ + trt.getHgaQueue();
        }

        localDefaultCategoryDataset.addValue(trtDocDelay / trtlist.size(), str1, cate3);
        localDefaultCategoryDataset.addValue(trtSldGap / trtlist.size(), str2, cate3);
        localDefaultCategoryDataset.addValue(trtHgaQ / trtlist.size(), str3, cate3);


        return localDefaultCategoryDataset;
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
